<template>
  <div class="search-history">
    <van-cell title="搜索历史">
        <div v-if="isDeleteShow">
            <span @click="$emit('clear-search-history')">全部删除</span>
            &nbsp;&nbsp;
            <span @click="isDeleteShow = false">完成</span>
        </div>
      
      <van-icon name="delete" v-else @click="isDeleteShow = true"/>
    </van-cell>
    <van-cell 
    :title="item"
    v-for="(item,index) in searchHistories"
    :key="index"
    @click="ondeleteclick(item,index)"
    >
      <van-icon v-show="isDeleteShow" name="close" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  props: {
      searchHistories: {
        type: Array,
        required: true
    }
  },
  data () {
    return {
        isDeleteShow:false,//控制删除显示状态
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
      ondeleteclick(item,index){
        //   两种状态 1删除 2不删除
        if (this.isDeleteShow) {
            this.searchHistories.splice(index,1);
            
        }else{
            // 非删除 进行搜索
             this.$emit('search', item)
        }
      }
  }
}
</script>

<style scoped lang="less"></style>
